package com.store.controller;

import com.store.domain.R;
import com.store.domain.dto.BookDto;
import com.store.service.BookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yu
 * @date 2024/6/26
 */
@RestController
@RequestMapping("book")
public class BookController {
    @Resource
    private BookService bookService;
    @GetMapping("{pageNum}/{pageSize}")
    public R getPageBook(@PathVariable Integer pageNum, @PathVariable Integer pageSize, BookDto bookDto) {
        return bookService.getPageBook(pageNum, pageSize, bookDto);
    }
    @PostMapping
    public R addBook(@RequestBody BookDto bookDto) {
        return bookService.addBook(bookDto);
    }
    @DeleteMapping("{id}")
    public R deleteBookById(@PathVariable Integer id) {
        return bookService.deleteBookById(id);
    }
    @GetMapping("backend/{id}")
    public R getBookById(@PathVariable Integer id) {
        return bookService.getBookById(id);
    }
    @PutMapping()
    public R updateBook(@RequestBody BookDto bookDto) {
        return bookService.updateBook(bookDto);
    }
    @PutMapping("{id}/{status}")
    public R updateBookStatus(@PathVariable Integer id, @PathVariable Integer status) {
        return bookService.updateBookStatus(id, status);
    }
    @DeleteMapping()
    public R deleteBatchByIds(@RequestBody Integer[] ids) {
        return bookService.deleteBatchByIds(ids);
    }


}
